import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 当前音量
    currentVolume: parseInt(window.sessionStorage.getItem('volume')) || 100,  
    // 当前的播放的地址
    currentSongUrl: window.sessionStorage.getItem('url') || '',
    // 当前的播放时间
    currentTimer: parseFloat(window.sessionStorage.getItem('time')) || 0,
    // 当前播放歌曲的信息
    currentSongInfo: JSON.parse(window.sessionStorage.getItem('item') ) || '',
    // 当前是播放还是暂停
    isFooterPlay: window.sessionStorage.getItem('isFooterPlay') || false,
    // 当前歌手数据
    currentSingerData: JSON.parse(window.sessionStorage.getItem('currentSingerData')) || '',
    // 当前播放的索引值
    currentPlayIndex: window.sessionStorage.getItem('currentPlayIndex') || 99999,
    // 当前正在播放的ID值
    currentID: window.sessionStorage.getItem('currentID') || 99999
  },
  mutations: {
    // 设置当前的url
    setCurrentSongUrl(state, url) {
      state.currentSongUrl = url;
      window.sessionStorage.setItem('url', url);
    },
    // 当前播放信息
    setCurrentSongInfo(state, item) {
      state.currentSongInfo = item;
      window.sessionStorage.setItem('item', JSON.stringify(item));
    },
    // 当前播放时间
    setCurrentTimer(state, time) {
      state.currentTimer = time;
      window.sessionStorage.setItem('time', time);
    },
    // 设置当前是播放还是暂停
    setIsFooterPlay(state, flag) {
      state.isFooterPlay = flag;
      window.sessionStorage.setItem('isFooterPlay', flag);
    },
    // 设置当前音量
    setCurrentVolume (state, volume) {
      state.currentVolume = volume;
      window.sessionStorage.setItem('volume', volume);
    },
    // 设置歌手详情数据
    setCurrentSingerData (state, data) {
      state.currentSingerData = data;
      window.sessionStorage.setItem('currentSingerData', JSON.stringify(data));
    },
    // 设置当前播放的索引值
    setCurrentPlayIndex (state, index) {
      state.currentPlayIndex = index;
      window.sessionStorage.setItem('currentPlayIndex', index);
    },
    // 设置当前播放的ID
    setCurrentID (state, id) {
      state.currentID = id;
      window.sessionStorage.setItem('currentID', id);
    }
  },
  actions: {
  },
  modules: {
  }
})
